

alter       function dbo.f_getrelationbcode
(
  @relationbtype integer,
  @relationbid integer
)  
returns varchar(40)
as  
begin 
--  select * from ts_billset
  declare  @relationbcode varchar(40)
  set @relationbcode  = ''
  if (@relationbtype is null)
  begin
    return @relationbcode
  end;
  select @relationbcode = 
    case @relationbtype 
      when 100 then (select bcode from tb_purplan where bid=@relationbid)    
      when 110 then (select bcode from tb_purorder where bid=@relationbid)
      when 120 then (select bcode from tb_purrequest where bid=@relationbid)
      when 130 then (select bcode from tb_purvalue where bid=@relationbid)
      when 140 then (select bcode from tb_purchase where bid=@relationbid)
      when 150 then (select bcode from tb_purexpend where bid=@relationbid)      
      when 160 then (select bcode from tb_purcontrol where bid=@relationbid)            
      when 200 then (select bcode from tb_saleplan where bid=@relationbid)
      when 205 then (select bcode from tb_salequote where bid=@relationbid)
      when 210 then (select bcode from tb_saleorder where bid=@relationbid)
      when 220 then (select bcode from tb_salesendout where bid=@relationbid)
      when 240 then (select bcode from tb_sale where bid=@relationbid)
      when 250 then (select bcode from tb_saleintegral where bid=@relationbid)
      when 260 then (select bcode from tb_saleinquiry where bid=@relationbid)
      when 300 then (select bcode from tb_depot where bid=@relationbid)
      when 310 then (select bcode from tb_otherrec where bid=@relationbid)
      when 315 then (select bcode from tb_othersend where bid=@relationbid)
      when 320 then (select bcode from tb_draw where bid=@relationbid)
      when 330 then (select bcode from tb_allot where bid=@relationbid)
      when 340 then (select bcode from tb_assembly where bid=@relationbid)
      when 345 then (select bcode from tb_disassembly where bid=@relationbid)
      when 350 then (select bcode from tb_lose where bid=@relationbid)
      when 360 then (select bcode from tb_check where bid=@relationbid)
      when 370 then (select bcode from tb_adjust where bid=@relationbid)
      when 390 then (select bcode from tb_pack where bid=@relationbid)      
      when 400 then (select bcode from tb_bankaccount where bid=@relationbid)
      when 410 then (select bcode from tb_expenditure where bid=@relationbid)
      when 420 then (select bcode from tb_otherincome where bid=@relationbid)
      when 500 then (select bcode from tb_gathering where bid=@relationbid)
      when 510 then (select bcode from tb_payment where bid=@relationbid)
      when 520 then (select bcode from tb_cancel where bid=@relationbid)
      when 600 then (select bcode from tb_FilRequest where bid=@relationbid)
      when 610 then (select bcode from tb_FilDistribute where bid=@relationbid)
      when 810 then (select bcode from tb_quality where bid=@relationbid)      
      when 1000 then (select bcode from tb_mnfplan where bid=@relationbid)
      when 1010 then (select bcode from tb_mnfmachining where bid=@relationbid)
      when 1020 then (select bcode from tb_mnfcheckaccept where bid=@relationbid)
      when 1040 then (select bcode from tb_mnfexpenditure where bid=@relationbid)
      when 1110 then (select bcode from tb_commission where bid=@relationbid)
      when 1120 then (select bcode from tb_comdraw where bid=@relationbid)
      when 1130 then (select bcode from tb_comcheckaccept where bid=@relationbid)
      when 1140 then (select bcode from tb_comexpenditure where bid=@relationbid)      
      when 1150 then (select bcode from tb_comexpproportion where bid=@relationbid)      
      when 2000 then (select bcode from tb_svcclient where bid=@relationbid)
      when 2010 then (select bcode from tb_svcorder where bid=@relationbid)
      when 2020 then (select bcode from tb_svcfinish where bid=@relationbid)
      when 2030 then (select bcode from tb_svcshipment where bid=@relationbid)              
      when 29010 then (select bcode from tfb_wagepiece where bid=@relationbid)
      when 29020 then (select bcode from tfb_wagemonth where bid=@relationbid)
      when 29030 then (select bcode from tfb_wagedivide where bid=@relationbid)
      when 29040 then (select bcode from tfb_wagefee where bid=@relationbid)      
      when 29050 then (select bcode from tfb_wagepay where bid=@relationbid)         
  end
  return @relationbcode
end














